<?php

namespace App\Admin\Actions\WithdrawAction;

use Encore\Admin\Actions\RowAction;
use Illuminate\Database\Eloquent\Model;
use App\Supports\Withdraw\WithdrawMoneyReturn;
use App\Services\ApplyGoldCoinWithdraw\RefuseGoldCoinWithdraw;

class RefuseWithdraw extends RowAction
{
    public $name = '拒绝';
    
    public function handle(Model $model)
    {
	    if ($model->isPaid()) {
		    return $this->response()->error('仅待处理提现申请可拒绝');
	    }
	    
	    if ($model->status == 'pending') {
		
		    app(RefuseGoldCoinWithdraw::class, [
			    'withdraw' => $model
		    ])->refuse();
		    
		    $model->update(['status' => 'refusal']);
		    
		    return $this->response()->success('提现已拒绝')->refresh();
		    
	    } else {
		    return $this->response()->error('仅待处理提现申请可拒绝');
	    }
    }
}
